<template>
    <div class="contener">
        <div class="tree-page">
            <!-- 左侧树 -->
            <div class="tree-menu">
                <base-tree
                    :data="baseTreeConfig.data"
                    :loading="baseTreeConfig.loading"
                    :currentNodeKey="baseTreeConfig.currentNodeKey"
                    :filterShow="baseTreeConfig.filterShow"
                    @NodeClick="handelTreeClick"
                />
            </div>
            <!-- 页面 -->
            <div class="page">
                <!-- 搜索 -->
                <transition
                    @before-enter="_beforeEnter"
                    @enter="_enter"
                    @after-enter="_afterEnter"
                    @before-leave="_beforeLeave"
                    @leave="_leave"
                    @after-leave="_afterLeave"
                >
                    <div
                        class="search-contener"
                        ref="searchContener"
                        v-show="searchFormConfig.searchContenerShow"
                    >
                        <base-form
                            :formItems="searchFormConfig.formItems"
                            :formData="searchFormConfig.formSubmit"
                            ref="searchForm"
                            @onButtonClick="searchBarButtonClick"
                        />
                    </div>
                </transition>
                <!-- 表格 -->
                <div class="datas-contener">
                    <!-- 表格操作项 -->
                    <div class="option-contener">
                        <data-options
                            @buttonClick="handelOptionClick"
                            :leftConfig="dataOptionConfig.leftConfig"
                        />
                    </div>
                    <!-- 表格展示项 -->
                    <div class="table-contener">
                        <base-table
                            ref="baseTable"
                            :tableData="baseTableConfig.tableData"
                            :tableHeader="baseTableConfig.tableHeader"
                            :tableConfig="baseTableConfig.tableConfig"
                            @handleSelection="tableDataSelected"
                        >
                            <template slot-scope="{ scope }">
                                <span v-if="scope.type === 'index'">
                                    {{ scope.$index + 1 }}
                                </span>
                                <el-switch
                                    v-if="scope.type === 'switch'"
                                    v-model="scope.row.status"
                                    active-value="0"
                                    inactive-value="1"
                                    @change="switchStatus(scope.row)"
                                />
                                <div v-if="scope.type === 'handle'">
                                    <el-button
                                        type="text"
                                        @click.stop="updateTableData(scope.row)"
                                        v-hasPermi="['system/user/update']"
                                        >修改</el-button
                                    >
                                    <el-button
                                        type="text"
                                        @click.stop="deleteTableData(scope.row)"
                                        v-hasPermi="['system/user/delete']"
                                        >删除</el-button
                                    >
                                    <el-dropdown
                                        class="more-dropdown"
                                        trigger="click"
                                        v-hasPermi="['system:user:resetPwd']"
                                    >
                                        <span class="el-dropdown-link">
                                            <i
                                                class="el-icon-d-arrow-right"
                                            ></i>
                                            更多
                                        </span>
                                        <el-dropdown-menu slot="dropdown">
                                            <el-dropdown-item
                                                v-hasPermi="[
                                                    'system:user:resetPwd'
                                                ]"
                                                icon="el-icon-key"
                                                @click.native="
                                                    resetPwd(scope.row)
                                                "
                                                >重置密码</el-dropdown-item
                                            >
                                        </el-dropdown-menu>
                                    </el-dropdown>
                                </div>
                            </template>
                        </base-table>
                    </div>
                    <!-- 分页 -->
                    <div class="paging-contener">
                        <pagin-ation
                            :size="paginationConfig.size"
                            :total="paginationConfig.total"
                            :type="paginationConfig.type"
                            :currentPage="paginationConfig.currentPage"
                            @PageNumber="pageNumberChange"
                            @PageSize="pageSizeChange"
                        />
                    </div>
                </div>
            </div>
        </div>
        <!-- 弹框 -->
        <el-dialog
            :title="dialogConfig.title"
            :visible.sync="dialogConfig.show"
            :width="dialogConfig.width"
            v-dialogDrag
            append-to-body
            :close-on-click-modal="false"
            :close-on-press-escape="false"
        >
            <!-- 筛选表格列 -->
            <div
                class="dialog-content"
                v-if="dialogConfig.key === 'tableColumn'"
            >
                <base-transfer
                    :transferConfig="tableColumnTransferConfig"
                    ref="baseTransfer"
                />
            </div>
            <!-- 新增 -->
            <div
                class="dialog-content"
                v-if="dialogConfig.key === 'addTableData'"
            >
                <base-form
                    :formItems="addFormConfig.formItems"
                    :formData="addFormConfig.formSubmit"
                    :formConfig="addFormConfig.formConfig"
                    :formRules="addFormConfig.formRule"
                    ref="addForm"
                    @onButtonClick="addFormButtonClick"
                />
            </div>
            <!-- 修改 -->
            <div
                class="dialog-content"
                v-if="dialogConfig.key === 'updateTableData'"
            >
                <base-form
                    :formItems="updateFormConfig.formItems"
                    :formData="updateFormConfig.formSubmit"
                    :formConfig="updateFormConfig.formConfig"
                    :formRules="updateFormConfig.formRule"
                    ref="updateForm"
                    @onButtonClick="updateFormButtonClick"
                />
            </div>
            <!-- 重置密码 -->
            <div class="dialog-content" v-if="dialogConfig.key === 'resetPwd'">
                <base-form
                    :formItems="resetPwdFromConfig.formItems"
                    :formData="resetPwdFromConfig.formSubmit"
                    :formConfig="resetPwdFromConfig.formConfig"
                    :formRules="resetPwdFromConfig.formRule"
                    ref="resetPwdForm"
                    @onButtonClick="resetPwdFormButtonClick"
                />
            </div>
            <!-- 上传 -->
            <div v-if="dialogConfig.key === 'uploadFile'">
                <file-import
                    @UploadEnd="handelUploadEnd"
                    :uploadType="uploadType"
                />
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button size="small" @click="handelCloseDialog"
                    >取 消</el-button
                >
                <el-button
                    size="small"
                    type="primary"
                    @click="handelCofimeDialog"
                    >确 定</el-button
                >
            </span>
        </el-dialog>
    </div>
</template>
<script>
import BaseTree from '@/components/baseTree/index'
import BaseForm from '@/components/baseForm/index'
import DataOptions from '@/components/dataOptions/index'
import BaseTable from '@/components/baseTable/index'
import PaginAtion from '@/components/pagination/index'
import BaseTransfer from '@/components/baseTransfer/index'
import globalMixin from '@/mixins/global'
import { deptTree } from '@/http/apis/system/dept/index'
import {
    userList,
    userDelete,
    userSave,
    userUpdate,
    resetPwd,
    exportExcel
} from '@/http/apis/system/user/index'
import { roleListAll } from '@/http/apis/system/role/index'
import { postListAll } from '@/http/apis/system/post/index'
import { getDictDatas } from '@/plugins/dict'
import {
    assemblyDataByTableColumn,
    setFormItemProp,
    setSelectFormart,
    getUuid
} from '@/utils/tool'
import { mapState } from 'vuex'
import {
    validPassWord,
    validEmail,
    validPhoneNumber,
    validRealName
} from '@/utils/validate'
import { getAES } from '@/utils/ase.js'
import FileImport from '@/components/fileImport/index'
export default {
    components: {
        BaseTree,
        BaseForm,
        DataOptions,
        BaseTable,
        PaginAtion,
        BaseTransfer,
        FileImport
    },
    computed: {
        ...mapState({
            userInfo: state => state.user.userInfo
        })
    },
    mixins: [globalMixin],
    dicts: ['sys_normal_disable', 'sys_user_sex'],
    data() {
        return {
            // 通用树组件配置
            baseTreeConfig: {
                // tree的数据
                data: [],
                // tree的加载状态
                loading: false,
                // tree选中的树
                currentNodeKey: '',
                // 过滤显示
                filterShow: true
            },
            // 搜索表单配置
            searchFormConfig: {
                formItems: [
                    [
                        {
                            ltype: 'input',
                            placeholder: '请输入账号名称',
                            label: '用户昵称',
                            prop: 'realName',
                            width: 'w-auto'
                        },
                        {
                            ltype: 'input',
                            placeholder: '请输入手机号',
                            label: '手机号码',
                            prop: 'phone',
                            width: 'w-auto'
                        },
                        {
                            ltype: 'select',
                            placeholder: '请选择状态',
                            label: '状态',
                            prop: 'status',
                            width: 'w-auto',
                            options: getDictDatas('sys_normal_disable')
                        },

                        {
                            ltype: 'button',
                            type: 'primary',
                            text: '搜索',
                            prop: 'searchDatas',
                            icon: 'el-icon-search',
                            width: 'w-auto',
                            loading: false
                        },
                        {
                            ltype: 'button',
                            type: 'default',
                            text: '重置',
                            prop: 'resetSearchForm',
                            icon: 'el-icon-refresh-right',
                            width: 'w-auto'
                        }
                    ]
                ],
                formSubmit: {
                    username: '',
                    phoneNumber: '',
                    status: '',
                    createTime: ''
                },
                formConfig: {
                    labelPosition: 'right', // label对齐方式
                    labelWidth: 'auto'
                },
                // 搜索控件是否显示
                searchContenerShow: true
            },
            // 数据操作项配置
            dataOptionConfig: {
                // 左侧按钮配置
                leftConfig: [
                    {
                        prop: 'addTableData',
                        label: '新增',
                        icon: 'el-icon-plus',
                        type: 'primary',
                        disabled: false,
                        hasPermi: ['system/user/save']
                    },
                    {
                        prop: 'deleteTableData',
                        label: '删除',
                        icon: 'el-icon-delete',
                        type: 'danger',
                        disabled: false,
                        hasPermi: ['system/user/delete']
                    },
                    {
                        prop: 'importTableData',
                        label: '导入',
                        icon: 'el-icon-upload2',
                        type: 'info',
                        disabled: false
                    },
                    {
                        prop: 'exportTableData',
                        label: '导出',
                        icon: 'el-icon-download',
                        type: 'info',
                        disabled: false
                    }
                ],
                // 右侧按钮配置
                rightConfig: [
                    {
                        prop: 'switchSearchStatus',
                        icon: 'el-icon-sort',
                        type: 'info',
                        disabled: false,
                        label: '搜索显隐'
                    },
                    {
                        prop: 'refreshTableData',
                        icon: 'el-icon-refresh-right',
                        type: 'info',
                        disabled: false,
                        label: '刷新'
                    }
                ]
            },
            // 表格配置
            baseTableConfig: {
                // 表格数据
                tableData: [],
                // 表格头数据
                tableHeader: [
                    {
                        type: 'selection',
                        width: 50,
                        fixed: 'left',
                        label: '选择',
                        visible: true
                    },
                    {
                        type: 'index',
                        label: '序号',
                        width: 50,
                        visible: true
                    },
                    {
                        prop: 'userName',
                        label: '账号名称',
                        visible: true
                    },
                    {
                        prop: 'realName',
                        label: '用户昵称',
                        visible: true
                    },
                    {
                        prop: 'phone',
                        label: '手机号码',
                        visible: true
                    },
                    {
                        prop: 'deptName',
                        label: '部门',
                        visible: true
                    },
                    {
                        prop: 'status',
                        type: 'switch',
                        label: '状态',
                        visible: true
                    },
                    {
                        prop: 'createTime',
                        label: '创建时间',
                        visible: true
                    },
                    {
                        label: '操作',
                        type: 'handle',
                        fixed: 'right',
                        visible: true
                    }
                ],
                // 表格配置
                tableConfig: {
                    loading: false
                },
                // 选中的表格数据
                tableCheckedDatas: []
            },
            // 分页配置
            paginationConfig: {
                type: 'md',
                size: 10,
                currentPage: 1,
                total: 100
            },
            // 弹框配置
            dialogConfig: {
                // 弹框标题
                title: '新增',
                // 是否显示
                show: false,
                // 宽度
                width: 'auto',
                // 弹框标识(用来区分弹框内容)
                key: ''
            },
            // 查询表格数据的参数
            queryTableParams: {
                pageNo: 0,
                pageSize: 10,
                entity: {}
            },
            // 表格列筛选配置
            tableColumnTransferConfig: {
                // 穿梭框的数据
                data: [],
                // 穿梭框的标题
                titles: ['显示', '隐藏']
            },
            // 新增表单配置
            addFormConfig: {
                // 表单项
                formItems: [
                    [
                        {
                            ltype: 'input',
                            placeholder: '请输入账号',
                            label: '账号',
                            prop: 'userName',
                            width: 'w-1'
                        },
                        {
                            ltype: 'input',
                            type: 'passWord',
                            placeholder:
                                '账号密码(8-16个字符，必须包含字母、数字、特殊字符 )',
                            label: '账号密码',
                            showPassword: true, // 显示密码
                            prop: 'passWord',
                            width: 'w-1'
                        }
                    ],
                    [
                        {
                            ltype: 'input',
                            placeholder:
                                '请输入用户名(长度为2~6位且不包含特殊字符)',
                            label: '用户名',
                            prop: 'realName',
                            width: 'w-1'
                        },
                        {
                            ltype: 'select',
                            placeholder: '请选择岗位',
                            label: '用户岗位',
                            prop: 'posts',
                            width: 'w-1',
                            multiple: true,
                            options: []
                        }
                    ],
                    [
                        {
                            ltype: 'treeSelect',
                            placeholder: '请选择部门',
                            label: '所在部门',
                            prop: 'deptId',
                            width: 'w-1',
                            multiple: false,
                            options: []
                        },
                        {
                            ltype: 'select',
                            placeholder: '请选择角色',
                            label: '用户角色',
                            prop: 'roles',
                            multiple: true,
                            width: 'w-1',
                            options: []
                        }
                    ],
                    [
                        {
                            ltype: 'input',
                            placeholder: '请输入手机号',
                            label: '手机号码',
                            prop: 'phone',
                            width: 'w-1'
                        },
                        {
                            ltype: 'input',
                            placeholder: '请输入邮箱',
                            label: '邮箱',
                            prop: 'email',
                            width: 'w-1'
                        }
                    ],
                    [
                        {
                            ltype: 'select',
                            placeholder: '请选择状态',
                            label: '状态',
                            prop: 'status',
                            width: 'w-1',
                            options: getDictDatas('sys_normal_disable')
                        },
                        {
                            ltype: 'radio',
                            placeholder: '请选择用户性别',
                            label: '用户性别',
                            prop: 'sex',
                            width: 'w-1',
                            options: getDictDatas('sys_user_sex')
                        }
                    ],
                    [
                        {
                            ltype: 'input',
                            type: 'textarea',
                            placeholder: '请输入备注',
                            label: '备注',
                            prop: 'remark',
                            width: 'w-1'
                        }
                    ]
                ],
                // 提交项
                formSubmit: {
                    realName: '',
                    phone: '',
                    status: '',
                    sex: '',
                    email: '',
                    deptId: null,
                    posts: [],
                    roles: [],
                    remark: ''
                },
                // 配置项
                formConfig: {
                    labelPosition: 'right', // label对齐方式
                    labelWidth: '80px'
                },
                // 验证项
                formRule: {
                    realName: [
                        {
                            required: true,
                            trigger: 'blur',
                            validator: validRealName
                        }
                    ],
                    phone: [
                        {
                            trigger: 'blur',
                            validator: validPhoneNumber
                        }
                    ],
                    email: [
                        {
                            trigger: 'blur',
                            validator: validEmail
                        }
                    ],
                    userName: [
                        {
                            required: true,
                            message: '请输入账号名',
                            trigger: 'blur'
                        }
                    ],
                    passWord: [
                        {
                            required: true,
                            message: '请输入密码'
                        },
                        {
                            trigger: 'blur',
                            validator: validPassWord
                        }
                    ],
                    deptId: [
                        {
                            required: true,
                            message: '请选择用户部门',
                            trigger: 'blur'
                        }
                    ],
                    posts: [
                        {
                            required: true,
                            message: '请选择用户岗位',
                            trigger: 'blur'
                        }
                    ],
                    roles: [
                        {
                            required: true,
                            message: '请选择用户角色',
                            trigger: 'blur'
                        }
                    ]
                }
            },
            // 修改表单配置
            updateFormConfig: {
                // 表单项
                formItems: [
                    [
                        {
                            ltype: 'input',
                            placeholder: '请输入账号',
                            label: '账号',
                            prop: 'userName',
                            width: 'w-1',
                            disabled: true
                        },
                        {
                            ltype: 'input',
                            type: 'passWord',
                            placeholder:
                                '账号密码(8-16个字符，必须包含字母、数字、特殊字符 )',
                            label: '账号密码',
                            disabled: true,
                            showPassword: true, // 显示密码
                            prop: 'passWord',
                            width: 'w-1'
                        }
                    ],
                    [
                        {
                            ltype: 'input',
                            placeholder:
                                '请输入用户名(长度为2~6位且不包含特殊字符)',
                            label: '用户名',
                            prop: 'realName',
                            width: 'w-1'
                        },
                        {
                            ltype: 'select',
                            placeholder: '请选择岗位',
                            label: '用户岗位',
                            prop: 'posts',
                            width: 'w-1',
                            multiple: true,
                            options: []
                        }
                    ],
                    [
                        {
                            ltype: 'treeSelect',
                            placeholder: '请选择部门',
                            label: '所在部门',
                            prop: 'deptId',
                            width: 'w-1',
                            multiple: false,
                            options: []
                        },
                        {
                            ltype: 'select',
                            placeholder: '请选择角色',
                            label: '用户角色',
                            prop: 'roles',
                            multiple: true,
                            width: 'w-1',
                            options: []
                        }
                    ],
                    [
                        {
                            ltype: 'input',
                            placeholder: '请输入手机号',
                            label: '手机号码',
                            prop: 'phone',
                            width: 'w-1'
                        },
                        {
                            ltype: 'input',
                            placeholder: '请输入邮箱',
                            label: '邮箱',
                            prop: 'email',
                            width: 'w-1'
                        }
                    ],
                    [
                        {
                            ltype: 'select',
                            placeholder: '请选择状态',
                            label: '状态',
                            prop: 'status',
                            width: 'w-1',
                            options: getDictDatas('sys_normal_disable')
                        },
                        {
                            ltype: 'radio',
                            placeholder: '请选择用户性别',
                            label: '用户性别',
                            prop: 'sex',
                            width: 'w-1',
                            options: getDictDatas('sys_user_sex')
                        }
                    ],
                    [
                        {
                            ltype: 'input',
                            type: 'textarea',
                            placeholder: '请输入备注',
                            label: '备注',
                            prop: 'remark',
                            width: 'w-1'
                        }
                    ]
                ],
                // 提交项
                formSubmit: {},
                // 配置项
                formConfig: {
                    labelPosition: 'right', // label对齐方式
                    labelWidth: '80px'
                },
                // 验证项
                formRule: {
                    realName: [
                        {
                            required: true,
                            trigger: 'blur',
                            validator: validRealName
                        }
                    ],
                    phone: [
                        {
                            trigger: 'blur',
                            validator: validPhoneNumber
                        }
                    ],
                    email: [
                        {
                            trigger: 'blur',
                            validator: validEmail
                        }
                    ],
                    // userName: [
                    //     {
                    //         required: true,
                    //         message: '请输入账号名',
                    //         trigger: 'blur'
                    //     }
                    // ],
                    deptId: [
                        {
                            required: true,
                            message: '请选择用户部门',
                            trigger: 'blur'
                        }
                    ],
                    posts: [
                        {
                            required: true,
                            message: '请选择用户岗位',
                            trigger: 'blur'
                        }
                    ],
                    roles: [
                        {
                            required: true,
                            message: '请选择用户角色',
                            trigger: 'blur'
                        }
                    ]
                }
            },
            // 重置表单配置
            resetPwdFromConfig: {
                // 表单项
                formItems: [
                    [
                        {
                            ltype: 'input',
                            type: 'passWord',
                            placeholder:
                                '账号密码(至少8个字符，需要包含大/小写字母，数字和特殊字符)',
                            label: '账号密码',
                            showPassword: true, // 显示密码
                            prop: 'passWord'
                        }
                    ]
                ],
                // 提交项
                formSubmit: {
                    passWord: '',
                    userName: ''
                },
                // 配置项
                formConfig: {
                    labelPosition: 'right', // label对齐方式
                    labelWidth: 'auto'
                },
                // 验证项
                formRule: {
                    passWord: [
                        {
                            required: true,
                            message: '请输入密码'
                        },
                        {
                            trigger: 'blur',
                            validator: validPassWord
                        }
                    ]
                }
            },
            uuid: getUuid(17),
            uploadType: '/system/user/importExcel?region=62'
        }
    },
    created() {
        this.initPage()
    },
    methods: {
        /**
         * 页面开始
         */
        async initPage() {
            // 查询部门树列表
            await this.queryDeptTree()
            // 设置用户表单的配置项
            this.setFormsItems()
            // 查询用户列表
            this.queryTableData(this.queryTableParams)
        },
        /**
         * 左侧部门树相关
         */
        /**
         * 查询部门树
         */
        async queryDeptTree() {
            this.baseTreeConfig.loading = true
            try {
                let res = await deptTree()
                if (res && res.data) {
                    this.baseTreeConfig.data = res.data
                } else {
                    this.baseTreeConfig.data = []
                }
                this.baseTreeConfig.loading = false
            } catch (error) {
                this.baseTreeConfig.loading = false
            }
        },
        /**
         * 树点击
         * @param {Object} params
         */
        handelTreeClick(params) {
            // 初始化查询条件
            this.initQueryParmas()
            this.baseTreeConfig.currentNodeKey = params.item.id
            // 组装查询条件
            this.queryTableParams.entity = {
                deptId: params.item.id
            }
            // 查询数据
            this.queryTableData(this.queryTableParams)
        },

        /**
         * 中间表格相关
         */

        /**
         * 查询表格数据
         */
        async queryTableData(params) {
            this.baseTableConfig.tableConfig.loading = true
            try {
                let res = await userList(params)
                if (res.data) {
                    this.baseTableConfig.tableData = this.baseTableConfig.tableData.concat(
                        res.data.list
                    )
                    this.paginationConfig.total = res.data.totalCount
                } else {
                    this.baseTableConfig.tableData = []
                    this.paginationConfig.total = 0
                }
                this.baseTableConfig.tableConfig.loading = false
            } catch (error) {
                this.baseTableConfig.tableConfig.loading = false
            }
        },
        /**
         * 表格数据被选中
         */
        tableDataSelected(rows) {
            this.baseTableConfig.tableCheckedDatas = rows
        },
        /**
         * 初始化查询参数
         */
        initQueryParmas() {
            this.queryTableParams = {
                pageNo: 0,
                pageSize: 10,
                entity: {
                    deptId: this.baseTreeConfig.currentNodeKey
                }
            }
            this.paginationConfig.size = 10
            this.paginationConfig.currentPage = 1
            this.baseTableConfig.tableData = []
        },
        /**
         * 页码变化
         */
        pageNumberChange(e) {
            this.queryTableParams.pageNo = e
            this.paginationConfig.currentPage = e
            this.baseTableConfig.tableData = []
            this.queryTableData(this.queryTableParams)
        },
        /**
         * 页大小变化
         */
        pageSizeChange(e) {
            // 页大小变化时，将当前页码设置为0
            this.queryTableParams.pageNo = 0
            // 将当前表格数据设置为空
            this.baseTableConfig.tableData = []
            this.queryTableParams.pageSize = e
            this.queryTableData(this.queryTableParams)
        },

        /**
         * 搜索栏相关
         */
        /**
         * 搜索栏按钮点击
         * @param {Object} params
         */
        searchBarButtonClick(params) {
            // 清空查询参数
            this.initQueryParmas()
            try {
                this[params.prop]()
            } catch (error) {
                throw new Error(error)
            }
        },
        /**
         * 重置搜索表单
         */
        resetSearchForm() {
            // 查询参数初始化
            this.initQueryParmas()
            // 重置搜索表单
            this.$refs.searchForm.resetForm()
            // 查询数据
            this.refreshTableData()
        },

        /**
         * 搜索数据
         */
        searchDatas() {
            this.$refs.searchForm.submitForm(() => {
                // 清空查询参数
                this.initQueryParmas()
                // 组装查询条件
                this.queryTableParams.entity = {
                    ...this.searchFormConfig.formSubmit
                }
                // 查询数据
                this.queryTableData(this.queryTableParams)
            })
        },

        /**
         * 操作栏相关
         */
        /**
         * 操作项点击
         * @param {*} params
         */
        handelOptionClick(params) {
            this[params] ? this[params]() : null
        },
        /**
         * 切换搜索栏的显示状态
         */
        switchSearchStatus() {
            this.searchFormConfig.searchContenerShow = !this.searchFormConfig
                .searchContenerShow
        },
        /**
         * 刷新表格数据
         */
        refreshTableData() {
            // 将当前表格数据设置为空
            this.baseTableConfig.tableData = []
            this.queryTableData(this.queryTableParams)
        },
        /**
         * 设置表格显示隐藏列(打开弹框)
         */
        switchTableColumn() {
            let dialogParams = {
                title: '显示/隐藏',
                width: 'auto',
                show: true,
                key: 'tableColumn'
            }
            // 设置参与表格列控制的属性（最后的数组为不参与隐藏显示设置的列）
            this.tableColumnTransferConfig.data = assemblyDataByTableColumn(
                this.baseTableConfig.tableHeader,
                'label',
                ['选择', '用户名称', '操作']
            )
            this.handelOpenDialog(dialogParams)
        },
        /**
         * 设置表格显示隐藏列(弹框确认)
         */
        switchTableColumnButtonClick() {
            let newData = this.$refs.baseTransfer.backCheckedData()
            if (newData && newData.length > 0) {
                this.baseTableConfig.tableHeader.forEach(ele => {
                    ele.visible = !newData.includes(ele.label)
                })
            } else {
                this.baseTableConfig.tableHeader.forEach(ele => {
                    ele.visible = true
                })
            }
            this.handelCloseDialog()
        },
        /**
         * 设置(新增、修改)表单的表单项
         */
        async setFormsItems() {
            // 重新设置新增、修改 表单的部门树数据配置
            this.addFormConfig.formItems = setFormItemProp(
                this.addFormConfig.formItems,
                'deptId',
                'options',
                this.baseTreeConfig.data
            )
            this.updateFormConfig.formItems = setFormItemProp(
                this.updateFormConfig.formItems,
                'deptId',
                'options',
                this.baseTreeConfig.data
            )
            // 获取角色下拉
            let roleRes = await roleListAll()
            if (roleRes && roleRes.data) {
                roleRes.data = setSelectFormart(roleRes.data, 'name', 'id')
                this.addFormConfig.formItems = setFormItemProp(
                    this.addFormConfig.formItems,
                    'roles',
                    'options',
                    roleRes.data
                )
                this.updateFormConfig.formItems = setFormItemProp(
                    this.updateFormConfig.formItems,
                    'roles',
                    'options',
                    roleRes.data
                )
            }
            // 获取岗位下拉
            let postRes = await postListAll()
            if (postRes && postRes.data) {
                postRes.data = setSelectFormart(postRes.data, 'name', 'id')
                this.addFormConfig.formItems = setFormItemProp(
                    this.addFormConfig.formItems,
                    'posts',
                    'options',
                    postRes.data
                )
                this.updateFormConfig.formItems = setFormItemProp(
                    this.updateFormConfig.formItems,
                    'posts',
                    'options',
                    postRes.data
                )
            }
        },
        /**
         * 新增表格数据(打开弹框)
         */
        addTableData() {
            // 打开新增弹框
            let dialogParams = {
                title: '新增',
                width: '60%',
                show: true,
                key: 'addTableData'
            }
            this.handelOpenDialog(dialogParams)
            this.$nextTick(() => {
                this.initAddForm()
            })
        },
        /**
         * 新增数据确认提交(弹框确认)
         */
        addFormButtonClick() {
            this.$refs['addForm'].submitForm(async res => {
                if (res) {
                    // 这里将控件选择后的数据转换为字符串
                    res.deptId = res.deptId.toString()
                    res.passWord = getAES(this.uuid, res.passWord.trim())
                    res.uuid = this.uuid
                    console.log('this.uuid', this.uuid)
                    let assRes = await userSave(res)
                    if (assRes && assRes.code === 0) {
                        this.$message.closeAll()
                        this.$message.success({ message: '新增成功！' })
                    } else {
                        this.$message.closeAll()
                        this.$message.error({ message: '新增失败！' })
                    }
                    this.handelCloseDialog()
                    // 查询数据
                    this.refreshTableData()
                    this.initAddForm()
                } else {
                    this.initAddForm()
                }
            })
        },
        /**
         * 初始化新增表单
         */
        initAddForm() {
            this.addFormConfig.formSubmit = {
                realName: '',
                phone: '',
                status: '',
                sex: '',
                email: '',
                deptId: null,
                posts: [],
                roles: [],
                remark: ''
            }
            this.$refs.addForm.resetForm()
        },
        /**
         * 修改表格数据(打开弹框)
         */
        async updateTableData(row) {
            this.updateFormConfig.formSubmit = this.$_.cloneDeep(row)
            // 这里将后端返回的dept id 转换成 数组
            this.updateFormConfig.formSubmit.deptId = [row.deptId]
            // 打开修改弹框
            let dialogParams = {
                title: '修改',
                width: '40%',
                show: true,
                key: 'updateTableData'
            }
            this.handelOpenDialog(dialogParams)
        },
        /**
         * 修改数据提交(弹框确认)
         */
        updateFormButtonClick() {
            this.$refs['updateForm'].submitForm(async res => {
                if (res) {
                    // 这里将控件选择后的数据转换为字符串
                    res.deptId = res.deptId.toString()
                    let assRes = await userUpdate(res)
                    if (assRes && assRes.code === 0) {
                        this.$message.closeAll()
                        this.$message.success({ message: '修改成功！' })
                    } else {
                        this.$message.closeAll()
                        this.$message.error({ message: '修改失败！' })
                    }
                    this.handelCloseDialog()
                    // 查询数据
                    this.refreshTableData()
                    this.initUpdateForm()
                } else {
                    this.initUpdateForm()
                }
            })
        },
        /**
         * 初始化修改表单
         */
        initUpdateForm() {
            this.updateFormConfig.formSubmit = {}
        },
        /**
         * 删除表格数据
         */
        deleteTableData(rows) {
            if (
                typeof rows === 'undefined' &&
                this.baseTableConfig.tableCheckedDatas.length > 0
            ) {
                rows = this.baseTableConfig.tableCheckedDatas
            }
            if (typeof rows !== 'undefined') {
                let params = []
                if (Array.isArray(rows) && rows.length) {
                    for (let i = 0; i < rows.length; i++) {
                        const element = rows[i]
                        params.push(element.userId)
                    }
                } else {
                    params = [rows.userId]
                }
                this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                })
                    .then(async () => {
                        let res = await userDelete(params)
                        if (res && res.code == 0) {
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            })
                        } else {
                            this.$message({
                                type: 'error',
                                message: '删除失败!'
                            })
                        }
                        // 查询数据
                        this.refreshTableData()
                    })
                    .catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        })
                    })
            } else {
                this.$message({
                    type: 'error',
                    message: '请选择数据！'
                })
            }
        },
        /**
         * 修改数据的状态
         * @param {*} row
         */
        async switchStatus(row) {
            this.$confirm(
                `是否将该用户状态设置为${
                    row.status === '0' ? '启用' : '停用'
                }?`,
                '提示',
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }
            )
                .then(async () => {
                    this.updateFormConfig.formSubmit = row
                    let assRes = await userUpdate(
                        this.updateFormConfig.formSubmit
                    )
                    if (assRes && assRes.code === 0) {
                        this.$message.closeAll()
                        this.$message.success({ message: '修改成功！' })
                    } else {
                        this.$message.closeAll()
                        this.$message.error({ message: '修改失败！' })
                    }
                    // 查询数据
                    this.refreshTableData()
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消修改'
                    })
                    // 查询数据
                    this.refreshTableData()
                })
        },

        /**
         * 导出excel数据
         */
        async exportTableData() {
            this.baseTableConfig.tableConfig.loading = true
            await exportExcel()
            this.baseTableConfig.tableConfig.loading = false
        },

        /**
         * 导入excel数据
         */
        async importTableData() {
            // 打开新增弹框
            let dialogParams = {
                title: '上传',
                width: '40%',
                show: true,
                key: 'uploadFile'
            }
            this.handelOpenDialog(dialogParams)
        },

        /**
         * 重置密码(打开弹框)
         */
        resetPwd(row) {
            // 打开修改弹框
            let dialogParams = {
                title: '重置密码',
                width: '40%',
                show: true,
                key: 'resetPwd'
            }
            // 重新设置新增、修改 表单的部门树数据配置
            this.resetPwdFromConfig.formItems = setFormItemProp(
                this.resetPwdFromConfig.formItems,
                'passWord',
                'label',
                `请输入${row.userName}的新密码`
            )
            this.resetPwdFromConfig.formSubmit.userName = row.userName
            this.handelOpenDialog(dialogParams)
        },
        /**
         * 重置密码表单提交
         */
        resetPwdFormButtonClick() {
            this.$refs['resetPwdForm'].submitForm(async res => {
                if (res) {
                    let params = {
                        userName: res.userName,
                        passWord: getAES(this.uuid, res.passWord.trim()),
                        uuid: this.uuid
                    }
                    let resetRes = await resetPwd(params)
                    if (resetRes && resetRes.code === 0) {
                        this.$message.closeAll()
                        this.$message.success({ message: '重置成功！' })
                    } else {
                        this.$message.closeAll()
                        this.$message.error({ message: '重置失败！' })
                    }
                    this.handelCloseDialog()
                    // 查询数据
                    this.refreshTableData()
                    this.initResetPwdForm()
                } else {
                    this.initResetPwdForm()
                }
            })
        },
        /**
         * 初始化修改密码表单
         */
        initResetPwdForm() {
            this.resetPwdFromConfig.formSubmit = {}
        },
        /**
         * 弹框相关
         */
        /**
         * 打开弹框
         * @param {*} params
         */
        handelOpenDialog(params) {
            this.dialogConfig = params
        },
        /**
         * 初始化弹框
         */
        handelInitDialog() {
            this.dialogConfig = {
                title: '',
                show: false,
                width: '',
                key: ''
            }
        },
        /**
         * 关闭弹框
         */
        handelCloseDialog() {
            this.handelInitDialog()
        },
        /**
         * 弹框确定
         */
        handelCofimeDialog() {
            // 表格列筛选的弹框
            if (this.dialogConfig.key === 'tableColumn') {
                this.switchTableColumnButtonClick()
            } else if (this.dialogConfig.key === 'addTableData') {
                this.addFormButtonClick()
            } else if (this.dialogConfig.key === 'updateTableData') {
                this.updateFormButtonClick()
            } else if (this.dialogConfig.key === 'resetPwd') {
                this.resetPwdFormButtonClick()
            }
        },
        handelUploadEnd(params) {
            if (params) {
                this.$message.closeAll()
                this.$message.success({ message: '导入成功！' })
                this.queryTableData(this.queryTableParams)
            } else {
                this.$message.closeAll()
                this.$message.error({ message: '导入失败！' })
            }
        }
    }
}
</script>
<style lang="scss" scoped>
.more-dropdown {
    margin-left: 10px;
}
.dialog-content {
    @include box_flex(
        $width: 100%,
        $height: auto,
        $direction: column,
        $justify: flex-start,
        $align: center
    );
}
</style>
